import math

protein_polarity = {
    'A': 8.1,  #/* A */
	'R': 10.5,  #/* R */
	'N': 11.6,  #/* N */
	'D': 13.0,  #/* D */
	'C': 5.5,  #/* C */
	'Q': 10.5,  #/* Q */
	'E': 12.3,  #/* E */
	'G': 9.0,  #/* G */
	'H': 10.4,  #/* H */
	'I': 5.2,  #/* I */
	'L': 4.9,  #/* L */
	'K': 11.3,  #/* K */
	'M': 5.7,  #/* M */
	'F': 5.2,  #/* F */
	'P': 8.0,  #/* P */
	'S': 9.2,  #/* S */
	'T': 8.6,  #/* T */
	'W': 5.4,  #/* W */
	'Y': 6.2,  #/* Y */
	'V': 5.9  #/* V */
}

protein_volume = {
	'A': 31.0,  #/* A */
	'R': 124.0,  #/* R */
	'N': 56.0,  #/* N */
	'D': 54.0,  #/* D */
	'C': 55.0,  #/* C */
	'Q': 85.0,  #/* Q */
	'E': 83.0,  #/* E */
	'G':  3.0,  #/* G */
	'H': 96.0,  #/* H */
	'I': 111.0,  #/* I */
	'L': 111.0,  #/* L */
	'K': 119.0,  #/* K */
	'M': 105.0,  #/* M */
	'F': 132.0,  #/* F */
	'P': 32.5,  #/* P */
	'S': 32.0,  #/* S */
	'T': 61.0,  #/* T */
	'W': 170.0,  #/* W */
	'Y': 136.0,  #/* Y */
	'V': 84.0  #/* V */
}

def init_ave_std() -> None:
    '''
    Calcuate the Average and Standard of the protein polarity and volume
    return: None
    '''
    global ave_polar, ave_volume, std_polar, std_volume
    ave_polar = ave_volume = std_polar = std_volume = 0.0
    for i in protein_polarity:
        ave_polar += protein_polarity[i]
    ave_polar /= len(protein_polarity)
    for i in protein_polarity:
        std_polar += (protein_polarity[i] - ave_polar) ** 2
    std_polar /= len(protein_polarity)
    std_polar = math.sqrt(std_polar)
    for i in protein_polarity: protein_polarity[i] = (protein_polarity[i] - ave_polar) / std_polar
    # print(ave_polar, std_polar, protein_polarity)
    for i in protein_volume:
        ave_volume += protein_volume[i]
    ave_volume /= len(protein_volume)
    for i in protein_volume:
        std_volume += (protein_volume[i] - ave_volume) ** 2
    std_volume /= len(protein_volume)
    std_volume = math.sqrt(std_volume)
    for i in protein_volume: protein_volume[i] = (protein_volume[i] - ave_volume) / std_volume
    # print(ave_volume, std_volume, protein_volume)
    return 

init_ave_std()

for i in protein_polarity:
    print("*Same " + i)
    print(complex(protein_polarity[i], protein_volume[i]), complex(protein_polarity[i], protein_volume[i]) * complex(protein_polarity[i], protein_volume[i]), ', mod =',
            abs(complex(protein_polarity[i], protein_volume[i]) * complex(protein_polarity[i], protein_volume[i])))
    for j in protein_polarity:
        if i != j:
            print(complex(protein_polarity[i], protein_volume[i]), '*', complex(protein_polarity[j], protein_volume[j]), '=',
            complex(protein_polarity[j], protein_volume[j]) * complex(protein_polarity[i], protein_volume[i]), ', mod =',
            abs(complex(protein_polarity[j], protein_volume[j]) * complex(protein_polarity[i], protein_volume[i])))